package com.example.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.book.model.Book;
import com.example.book.repository.BookList;
import com.example.book.web.WebUtil;

@WebServlet("/detail")
public class BookDetailServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ServletContext sc = this.getServletContext();
		BookList bl = WebUtil.getBookList(sc);
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println(" <body>");
		String isbn = request.getParameter("isbn");
		Book book = bl.getBook(isbn);
		out.println("<br>");
		out.println("<a href='http://localhost:8080/BBStore/AddToCart?isbn="+isbn+"'>Ajouter au panier</a>");
		out.println("<br>");
		out.println("Le titre du livre est " + book.getTitle());
		out.println("<br>");
		out.println("L'auteur du livre est " + book.getAuthor());
		out.println("<br>");
		out.println("Le prix du livre est "+book.getPrice());
		out.println("<br>");
		out.println("<a href='http://localhost:8080/BBStore/catalog'>Retour au catalogue</a>");
		out.println("<br>");
		out.println(" </body>");
		out.println("</html>");
		
		
	}

}
